using System;

using Impact.Web.Foundation;
using Impact.Views;
using Impact.Infrastructure.Exceptions;
using Impact.Model.Objects;

namespace Impact.Web.Controls
{
    public partial class DisplayTag : Impact.Web.Foundation.DynamicPageControlBase, Impact.Views.IContentControl
    {

        /// <summary>
        /// Loads the tag into the controls that need it
        /// </summary>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            Check.Require(tag, "DataSource is required");

            this.tagText.Text = tag.Text;
            this.articleRepeater.DataSource = tag.Articles;
            this.articleRepeater.DataBind();

        }

        /// <summary>
        /// Retrieves the title for the page this control is building
        /// </summary>
        protected override string PageTitle
        {
            get { return string.Format("Articles tagged with: {0}", Tag.Text); }
        }

        private Tag tag;

        /// <summary>
        /// Gets or Sets the tag that will be displayed by this control
        /// </summary>
        public Tag Tag
        {
            get { return tag; }
            set { tag = value; }
        }


        #region IContentControl Members

        /// <summary>
        /// Sets a Tag as the datasource for this control
        /// </summary>
        public object DataSource
        {
            set { tag = (Tag)value; }
        }

        /// <summary>
        /// called to perform initialization before the control loads
        /// </summary>
        public void PreInit()
        {
        }

        #endregion
    }
}